package com.example.logintest.util;

import com.example.logintest.bean.User;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class CreateJWT {

    public static String getToken(User user){
        String key = "by123";
        JwtBuilder jwtBuilder = Jwts.builder().setId(user.getId()+"")
                .setSubject(user.getUsername())
                .setIssuedAt(new Date())
                .signWith(SignatureAlgorithm.HS256, key);
                //.setExpiration(new Date(new Date().getTime()+86400000));
        System.out.println(jwtBuilder.compact());
        return jwtBuilder.compact();
    }

}
